<?php
/**
 * RSS输出 - JBlog
 * 
 * @copyright (c) 2008-2010 JBlog (www.lisijie.org)
 * @author lisijie <lisijie86@gmail.com>
 * @version $Id: rss.php 551 2010-07-22 09:35:52Z lisijie86 $
*/

require('include/common.php');

$cachetime = 3600; //缓存时间/秒

@header('Content-Type: text/xml; charset=utf-8');

$pagesize = (int)config('pagesize');

$blogurl = config('blogurl').'/';
$atom = $blogurl.'rss.php';
$title = config('blogname');
$link = $blogurl;

$cateid = intval($_GET['cate']);
$wheresql = '';
if ( $cateid ) {
	$wheresql = " AND cateid = '$cateid' ";
	$atom .= '?cate='.$cateid;
	$description = $_CACHE['cate'][$cateid]['descriotion'];
	$title = $_CACHE['cate'][$cateid]['catename'] . ' - ' . $title;
} else {
	$description = config('description');
}

$sql = "SELECT id,cateid,alias,title,excerpt,dateline FROM ".tname('post')." 
WHERE 1 $wheresql AND `type` = 'blog' AND `status` = '1' AND `password` = '' 
ORDER BY dateline DESC LIMIT $pagesize";

$rssdata = array();
$query = $db->query($sql);
while ($row = $db->fetch_array($query)) {
	$rssdata[] = array(
		'title' => $row['title'],
		'link' => $blogurl.url('mod=post&id='.$row['id'].'&alias='.$row['alias']),
		'description' => ubb_decode($row['excerpt']),
		'comments' => $blog_url.$comments,
		'category' => $_CACHE['cate'][$row['cateid']]['name'],
		'pubDate' => get_date($row['dateline'],'r')
	);
}

echo '<?'.'xml version="1.0" encoding="utf-8"?'.'>',"\n";
?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" >
<channel>
	<title><?php echo $title?></title>
	<atom:link href="<?php echo $atom?>" rel="self" type="application/rss+xml" />
	<link><?php echo $link?></link>
	<description><?php echo $description?></description>
	<language>zh-cn</language>
	<pubDate><?php echo get_date(NOW,'r')?></pubDate>
	<generator>JBlog v<?php echo JBLOG_VERSION?></generator>
	<?php
	foreach ($rssdata as $rss) {
	?>
	<item>
		<title><?php echo $rss['title']?></title>
		<link><?php echo $rss['link']?></link>
		<description><![CDATA[<?php echo $rss['description']?>]]></description>
		<category><?php echo $rss['category']?></category>
		<comments><?php echo $rss['comments']?></comments>
		<guid><?php echo $rss['link']?></guid>
		<pubDate><?php echo $rss['pubDate']?></pubDate>
	</item>

	<?php
	}
	?>
</channel>
</rss>